import { BasicColumn, FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';

export const columns: BasicColumn[] = [
  {
    title: '标题',
    width: 150,
    dataIndex: 'title',
  },
  // {
  //   title: '接收类型',
  //   width: 150,
  //   dataIndex: 'busType_dictText',
  // },
  {
    title: '消息类型',
    dataIndex: 'category_dictText',
    width: 100,
  },
  {
    title: '发布人',
    width: 100,
    dataIndex: 'sender_dictText',
  },
  {
    title: '优先级',
    dataIndex: 'priority',
    width: 70,
    customRender: ({ text }) => {
      const color = text == '0' ? 'blue' : text == '1' ? 'yellow' : 'red';
      return render.renderTag(render.renderDict(text, 'notify_priority'), color);
    },
  },
  {
    title: '通告对象',
    dataIndex: 'recipientFilterType',
    width: 100,
    customRender: ({ text }) => {
      return render.renderDict(text, 'notify_recipient_filter_type');
    },
  },
  {
    title: '发布状态',
    dataIndex: 'status',
    width: 70,
    customRender: ({ text }) => {
      const color = text == '0' ? 'red' : text == '1' ? 'green' : 'gray';
      return render.renderTag(render.renderDict(text, 'notify_send_status'), color);
    },
  },
  {
    title: '发布时间',
    width: 100,
    dataIndex: 'publishTime',
  },
  {
    title: '撤销时间',
    width: 100,
    dataIndex: 'cancelTime',
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'title',
    label: '标题',
    component: 'JInput',
    colProps: { span: 8 },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: 'id',
    component: 'Input',
    show: false,
  },
  {
    field: 'title',
    label: '标题',
    component: 'Input',
    required: true,
    componentProps: {
      placeholder: '请输入标题',
    },
    // update-begin--author:liaozhiyang---date:20240701---for：【TV360X-1632】标题过长保存报错，长度校验
    dynamicRules() {
      return [
        {
          validator: (_, value) => {
            return new Promise<void>((resolve, reject) => {
              if (value.length > 100) {
                reject('最长100个字符');
              }
              resolve();
            });
          },
        },
      ];
    },
    // update-end--author:liaozhiyang---date:20240701---for：【TV360X-1632】标题过长保存报错，长度校验
  },
  {
    field: 'msgAbstract',
    label: '摘要',
    component: 'InputTextArea',
    required: true,
  },
  {
    field: 'immortal',
    label: '永久有效',
    defaultValue: 1,
    component: 'JDictSelectTag',
    required: true,
    componentProps: {
      type: 'radio',
      dictCode: 'notify_immortal',
      placeholder: '请选择消息是否永久有效',
      stringToNumber: true,
    },
  },
  // {
  //   field: 'deadline',
  //   label: '截至日期',
  //   component: 'DatePicker',
  //   componentProps: {
  //     showTime: true,
  //     valueFormat: 'YYYY-MM-DD HH:mm:ss',
  //     placeholder: '请选择截至日期',
  //   },
  //   ifShow: ({ values }) => values.immortal == 0,
  // },
  // {
  //   field: 'busType',
  //   label: '接收类型',
  //   defaultValue: 1,
  //   component: 'JDictSelectTag',
  //   required: true,
  //   componentProps: {
  //     type: 'radio',
  //     dictCode: 'msg_bus_type',
  //     placeholder: '请选择接收方式',
  //     stringToNumber: true,
  //   },
  //   //dynamicDisabled: ({ values }) => values.busType,
  // },
  {
    field: 'category',
    label: '消息类型',
    defaultValue: 1,
    component: 'JDictSelectTag',
    required: true,
    componentProps: {
      type: 'radio',
      dictCode: 'notify_category',
      placeholder: '请选择消息类型',
      stringToNumber: true,
    },
    // ifShow: ({ values }) => values.busType == 1,
  },
  {
    field: 'recipientFilterType',
    label: '接收用户',
    defaultValue: 1,
    component: 'JDictSelectTag',
    required: true,
    componentProps: {
      type: 'radio',
      dictCode: 'notify_recipient_filter_type',
      placeholder: '请选择发布范围',
      stringToNumber: true,
    },
  },
  {
    field: 'userRoleIds',
    label: '指定角色',
    component: 'JSelectRole',
    required: true,
    componentProps: {
      rowKey: 'id',
      labelKey: 'name',
    },
    ifShow: ({ values }) => values.recipientFilterType == 2,
  },
  {
    field: 'userDeptIds',
    label: '指定组织',
    component: 'JSelectDept',
    required: true,
    componentProps: {
      rowKey: 'id',
      labelKey: 'title',
    },
    ifShow: ({ values }) => values.recipientFilterType == 3,
  },
  {
    field: 'userTypeIds',
    label: '指定用户类型',
    defaultValue: 'BACKEND',
    component: 'JDictSelectTag',
    required: true,
    componentProps: {
      mode: 'multiple',
      dictCode: 'user_type',
      placeholder: '请选择用户类型',
      stringToNumber: false,
      showChooseOption: false,
    },
    ifShow: ({ values }) => values.recipientFilterType == 4,
  },
  {
    field: 'userIds',
    label: '指定用户',
    component: 'JSelectUser',
    required: true,
    componentProps: {
      rowKey: 'id',
      // update-begin--author:liaozhiyang---date:20240701---for：【TV360X-1627】通知公告用户选择组件没翻译
      labelKey: 'realname',
      // update-end--author:liaozhiyang---date:20240701---for：【TV360X-1627】通知公告用户选择组件没翻译
    },
    ifShow: ({ values }) => values.recipientFilterType == 5,
  },
  {
    field: 'priority',
    label: '优先级',
    defaultValue: 3,
    component: 'JDictSelectTag',
    required: true,
    componentProps: {
      type: 'radio',
      dictCode: 'notify_priority',
      placeholder: '请选择消息发送优先级',
      stringToNumber: true,
    },
  },
  {
    field: 'content',
    label: '内容',
    component: 'Input',
    render: render.renderTinymce,
  },
];
